package com.donleo.job.quartz;

import java.util.Date;

/**
 * 缺点:程序一旦启动不能修改执行周期
 *
 * @author liangd
 * @since 2021-03-03 17:40
 */
public class QuartzTest {
    public static void main(String[] args) {
        // 添加任务A
        QuartzManager.getInstance().addJob("A", "001", "A", "001", A.class,
                "0/5 * * * * ?", "A", "C");
        QuartzManager.getInstance().startJobs();
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(new Date());

        // 修改任务A的出发时间设定
        QuartzManager.getInstance().modifyJobTime("A", "001", "A", "001", "0/4 * * * * ?");
        try {
            Thread.sleep(20000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(new Date());

        // 添加任务B
        QuartzManager.getInstance().addJob("B", "002", "B", "002", B.class,
                "0/6 * * * * ?", "B");
        try {
            Thread.sleep(20000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(new Date());
        // 删除任务A
        QuartzManager.getInstance().removeJob("A", "001", "A", "001");
        try {
            Thread.sleep(20000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        QuartzManager.getInstance().shutdownJobs();
    }
}
